package top.vains.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import top.vains.entity.Role;
import top.vains.entity.User;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author vains
 * @since 2020-02-17
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 获取用户拥有的角色
     * @param userId 用户id
     * @return 拥有的角色
     */
    @Select("SELECT r.* FROM `user` u JOIN user_role ur ON u.user_id = ur.user_id JOIN role r ON ur.role_id = r.id WHERE u.user_id = #{userId}")
    List<Role> getUserHaveRole(Integer userId);

}
